import { AutoGuideStepBase } from "./AutoGuideStepBase";
import { IAutoGuideSteper } from "./IAutoGuideSteper";
import { AutoGuideData } from "../AutoGuideData";
import { Window } from "../../../../../component/window/Window";
import { AutoGuideType } from "../AutoGuideType";
import { DisplayUtil } from "../../../../../common/DisplayUtil";
import { LayerManager } from "../../../../manager/LayerManager";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { Log } from "../../../../../../com/gengine/debug/Log";
import { AutoGuideClickType } from "../AutoGuideClickType";
import { EffectManager } from "../../../../manager/EffectManager";
//class AutoGuideWindowSteper
    
    export  class AutoGuideWindowSteper extends AutoGuideStepBase implements IAutoGuideSteper
    {
        constructor()
        {
            super();
            return;
        }

        public guide(arg1: AutoGuideData, arg2: Window=null): void
        {
            if (arg1 == null) 
            {
                return;
            }
            if (!(arg1.guideType == AutoGuideType.Window) || arg1.guideTypeValue == null || arg1.guideTypeValue == "") 
            {
                return;
            }
            if (arg2 == null) 
            {
                arg2 = DisplayUtil.getChildByPropety(LayerManager.windowLayer, "winTitleName", arg1.guideTypeValue) as Window;
            }
            if (arg2 == null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideDelDoingRecord, arg1));
                return;
            }
            _data = arg1;
            var loc1=DisplayUtil.getChildByPropety(arg2, "name", arg1.clickChildName as string);
            if (loc1 == null) 
            {
                Log.debug("窗口自动指引，在窗口：" + arg2.winTitleName + "中找不到name为：" + arg1.guideTypeValue + " 的儿子儿儿子， 指引中断");
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, arg1));
                return;
            }
            if (arg1.needMask) 
            {
                showMask(arg2.highestContentContainer, loc1);
            }
            if (arg1.needArrow) 
            {
                showArrow(arg2.highestContentContainer, arg1, loc1);
            }
            if (arg1.needLineBox) 
            {
                showLineBox(arg2.highestContentContainer, loc1);
            }
            _datas[loc1] = arg1;
            if (arg1.clickType != AutoGuideClickType.Click) 
            {
                loc1.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.clickWinChildHandler, false, 0, true);
            }
            else 
            {
                loc1.addEventListener(flash.events.MouseEvent.CLICK, this.clickWinChildHandler, false, 0, true);
            }
            return;
        }

        /* internal  */clickWinChildHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as Object /* flash.display.DisplayObject */;
            var loc2=_datas[loc1];
            loc1.removeEventListener(flash.events.MouseEvent.CLICK, this.clickWinChildHandler);
            loc1.removeEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.clickWinChildHandler);
            if (loc2 != null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, loc2));
                _datas[loc1] = null;
            }
            DisplayUtil.removeMe(mask);
            DisplayUtil.removeMe(arrow);
            DisplayUtil.removeMe(_lineBox);
            EffectManager.disposeLineBox(_lineBox);
            return;
        }

        public stop(arg1: AutoGuideData=null): void
        {
            DisplayUtil.removeMe(mask);
            DisplayUtil.removeMe(arrow);
            DisplayUtil.removeMe(_lineBox);
            EffectManager.disposeLineBox(_lineBox);
            return;
        }
    }
